package models

import (
	"gorm.io/gorm"
	"time"
)

// Friend 好友关系模型
type Friend struct {
	gorm.Model
	UserID    int       `json:"user_id" gorm:"not null"`
	FriendID  int       `json:"friend_id" gorm:"not null"`
	CreatedAt time.Time `json:"created_at"`
}

func AddFriend(userID, friendID int) error {
	friend := &Friend{UserID: userID, FriendID: friendID, CreatedAt: time.Now()}
	return GetDB().Create(friend).Error
}

func GetFriends(userID int) ([]Friend, error) {
	var friends []Friend
	err := GetDB().Where("user_id = ?", userID).Find(&friends).Error
	return friends, err
}

func DeleteFriend(userID, friendID int) error {
	return GetDB().Where("user_id = ? AND friend_id = ?", userID, friendID).Delete(&Friend{}).Error
}
